#include<iostream>
#include<pthread.h>
#include<unistd.h>
#include<cstdio>
using namespace std;
pthread_mutex_t lock;
pthread_cond_t cond;

void *Run(void* arg)
{ 
  printf("%s run....\n",(char*)arg);
  pthread_detach(pthread_self());
//  cout<<(char*)arg<<" run..."<<endl; 
  while(1)
  {
    pthread_cond_wait(&cond,&lock);//条件不满足，阻塞在这
   // cout<<"thread: "<<pthread_self()<<" 活动..."<<endl;
    printf("thread: %x 活动......\n",pthread_self());

  }
}

int main()
{
  pthread_mutex_init(&lock,nullptr);
  pthread_cond_init(&cond,nullptr);

  pthread_t t1,t2,t3;
  pthread_create(&t1,nullptr,Run,(void*)"thread 1");
  pthread_create(&t2,nullptr,Run,(void*)"thread 2");
  pthread_create(&t3,nullptr,Run,(void*)"thread 3");
// 控制
  while(1)
  {
    getchar();
    pthread_cond_broadcast(&cond);
    
  }
  

  pthread_mutex_destroy(&lock);
  pthread_cond_destroy(&cond);
  return 0;
}
